package com.zmzncs.lmtc.module.order.controller;


import com.zmzncs.lmtc.common.pojo.Rest;
import com.zmzncs.lmtc.common.util.JsonUtil;
import com.zmzncs.lmtc.common.util.RestUtil;
import com.zmzncs.lmtc.module.order.pojo.order_card.OrderCardDTO;
import com.zmzncs.lmtc.module.order.pojo.order_card.OrderCardTableVO;
import com.zmzncs.lmtc.module.order.service.OrderCardService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 任建波
 * @since 2020-10-19
 */
@Api(tags = "订单")
@RestController
@RequestMapping("/order/card")
@Validated
@Slf4j
public class OrderCardController {

    @Autowired
    OrderCardService orderCardService;

    @ApiOperation(value = "根据订单号查询订单使用的会员卡")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "请求头token", required = true),
            @ApiImplicitParam(paramType = "query", name = "orderId", value = "订单编号" , required = true ),
    })
    @GetMapping(value = "getOrderCardByOrderCode")
    public Rest<List<OrderCardTableVO>> getOrderCardByOrderCode(@NotNull String orderCode) {
        List<OrderCardDTO> orderCardDTOList = orderCardService.getOrderCardByOrderCode(orderCode);
        List<OrderCardTableVO> orderCardTableVOList = JsonUtil.listTransform(orderCardDTOList, OrderCardTableVO.class);

        return RestUtil.success(orderCardTableVOList);
    }

}

